/**
 * Created by lrqrun on 17-1-3.
 */
$(document).ready(function(){
	if(Notification.permission !== "granted"){
		Notification.requestPermission();
	}else{
		setInterval(get_unread_notices, 5000);
	}
});

var get_unread_notices = function(){
	$.ajax({
		url: "/get_unread_notices/",
		data: {},
		success: function(data){
			if(data.status == 1){
				var notice = new Notification("[运维系统]You've got a new notification", {
					// icon: 'http://cdn.sstatic.net/stackexchange/img/logos/so/so-icon.png',
					body: data.subject,
				});
				notice.onclick = function(){
					window.location.assign(data.callback);
				};
				notice.onshow = function(){
					setTimeout(function(){
						notice.close();
					}, 5000)
				};
				$("#unread_count").html(data.count);
			}
		}
	});
};
